#-*- coding: utf-8 -*-


import logging
# 写入文件的处理器===========

# create logger  记录器
logger = logging.getLogger('simple_example')
logger.setLevel(logging.DEBUG)

# create console handler and set level to debug
# ch = logging.StreamHandler() 输出到终端的  处理器
ch = logging.FileHandler('mylog.log',encoding='utf-8')
ch.setLevel(logging.DEBUG)

# create formatter 格式器
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')

# add formatter to ch 将格式器添加到处理器中
ch.setFormatter(formatter)

# add ch to logger  处理器添加到记录器中
logger.addHandler(ch)

# 终端打印日志处理器

ch_1 = logging.StreamHandler()
ch_1.setLevel(logging.DEBUG)

# create formatter
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')

# add formatter to ch
ch_1.setFormatter(formatter)

# add ch to logger
logger.addHandler(ch_1)

# 'application' code
logger.debug('debug message')
logger.info('info message')
logger.warning('warn message')
logger.error('error message')
logger.critical('critical message')

